package com.handinfo.android.game;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWBitmap;
import com.handinfo.android.core.object.Actor;
import com.handinfo.android.core.object.Animation;
import com.handinfo.android.core.resource.DWSerializableFactory;
import com.handinfo.android.core.resource.ResHead;
import com.handinfo.android.core.resource.ResourceManager;
import com.handinfo.android.game.item.ItemConstants;
import com.handinfo.android.utils.Tools;

public class IconManger
{
	public static final String DIR_PATH = "/img/icon/big_datubiao_";
	
	public static final String BLACK_PATH = "/img/icon/big_black_";

	public static final int BANGDING = 250;
	
	public static final int JINGHUN = 210;
	
	public static final int PINZHI = 260;

	public static final int GEM = 251;
	
	public static Bitmap m_bangding = getBangding();
	
	public static Bitmap m_jinghun = getJinghun();
	
	public static Bitmap[] m_vipIcon = getVipIcon(6);
	
	public static Bitmap[] m_wantedIcon = getWantedIcon();
	
	public static Bitmap[] m_factionIcon = getFactionIcon();
	
	public static Bitmap m_null = getIcon("/img/icon/big_datubiao_69.gnp");
	
	public static Bitmap m_isLimit = getIcon("/img/newui/beibaojinyong_1.gnp");
	
	public static Bitmap m_sellShop = getSellShop("/img/newui/ditan_huowu2.gnp");
	
	public static Bitmap m_sellTitle = getSellTitle("/img/newui/baitanbg_1.gnp");
	
	public static Bitmap[] m_soul = getSoulIcon();
	
	public static Actor[] m_soulActor = getSoulActor();
	
	public static IconManger m_instance;

	public static IconManger getInstance()
	{
		if (m_instance == null) {
			m_instance = new IconManger();
		}
		return m_instance;
	}

	/**
	 * 绑定的小锁图标
	 * */
	public static Bitmap getBangding()
	{
		StringBuilder buff = new StringBuilder();
		buff.append(DIR_PATH);
		buff.append(BANGDING);
		buff.append(DWSerializableFactory.EXTENSION_IMG);
		String url = buff.toString();
		buff = null;
		ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if(bitmap == null){
			Tools.debugPrintln("IconManager getBangding() loadResource null");
			return m_null;
		}
		Bitmap map = bitmap.getImage();
		if( map == null){
			map = m_null;
		}
		return map;
	}
	
	/**
	 * 精魂的图标
	 * */
	public static Bitmap getJinghun()
	{
		StringBuilder buff = new StringBuilder();
		buff.append(DIR_PATH);
		buff.append(JINGHUN);
		buff.append(DWSerializableFactory.EXTENSION_IMG);
		String url = buff.toString();
		buff = null;
		ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if(bitmap == null){
			Tools.debugPrintln("IconManager getJinghun() loadResource null");
			return m_null;
		}
		Bitmap map = bitmap.getImage();
		if( map == null){
			map = m_null;
		}
		return map;
	}

	/**
	 * @param int iconId
	 * */
	public Bitmap getIcon(int iconId)
	{
		StringBuilder buff = new StringBuilder();
		buff.append(DIR_PATH);
		buff.append(iconId);
		buff.append(DWSerializableFactory.EXTENSION_IMG);
		String url = buff.toString();
		buff = null;
		Tools.debugPrintln("IconManger getIcon url=" + url);
		ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if(bitmap == null){
			Tools.debugPrintln("IconManager getIcon(int iconId) loadResource null");
			return m_null;
		}
		Bitmap map = bitmap.getImage();
		if( map == null){
			map = m_null;
		}
		return map;
	}
	
	/**
	 * @param int iconId
	 * */
	public Bitmap getblackIcon(int iconId)
	{
		StringBuilder buff = new StringBuilder();
		buff.append(BLACK_PATH);
		buff.append(iconId);
		buff.append(DWSerializableFactory.EXTENSION_IMG);
		String url = buff.toString();
		buff = null;
		Tools.debugPrintln("IconManger getblackIcon url=" + url);
		ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if(bitmap == null){
			Tools.debugPrintln("IconManager getblackIcon(int iconId) loadResource null");
			return m_null;
		}
		Bitmap map = bitmap.getImage();
		if( map == null){
			map = m_null;
		}
		return map;
	}
	
	/**
	 * @param String url
	 * */
	public static Bitmap getIcon(String url)
	{
		Tools.debugPrintln("IconManger getIcon url=" + url);
		ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if(bitmap == null){
			Tools.debugPrintln("IconManager getIcon(String url) loadResource null");
			return m_null;
		}
		Bitmap map = bitmap.getImage();
		return map;
	}


	/**
	 * @param int index 槽索引
	 * @param byte isHave 是否有宝石
	 * */
	public Bitmap getEquipGemIcon(int index, byte ishave)
	{
		int i = index;
		if (ishave == ItemConstants.含有宝石_是) {
			i += 4;
		}
		StringBuilder buff = new StringBuilder();
		buff.append(DIR_PATH);
		buff.append((GEM+i));
		buff.append(DWSerializableFactory.EXTENSION_IMG);
		String url = buff.toString();
		buff = null;
		Tools.debugPrintln("IconManger getEquipGemIcon url=" + url);
		ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if(bitmap == null){
			Tools.debugPrintln("IconManager getEquipGemIcon(int index, byte ishave) loadResource null");
			return m_null;
		}
		Bitmap map = bitmap.getImage();
		if( map == null){
			map = m_null;
		}
		return map;
	}

	/**
	 * 品质的图片
	 * */
	public Bitmap getPinzhi(int Quality)
	{
		if(Quality < 0 || Quality > ItemConstants.稀有度_红){
			Quality = ItemConstants.稀有度_白;
		}
		StringBuilder buff = new StringBuilder();
		buff.append(DIR_PATH);
		buff.append((PINZHI+Quality));
		buff.append(DWSerializableFactory.EXTENSION_IMG);
		String url = buff.toString();
		buff = null;
		ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if(bitmap == null){
			Tools.debugPrintln("IconManager getPinzhi(int Quality) loadResource null");
			return m_null;
		}
		Bitmap map = bitmap.getImage();
		if( map == null){
			map = m_null;
		}
		return map;
	}
	
	/**
	 * @param String url
	 * */
	public static Bitmap getSellShop(String url)
	{
		Tools.debugPrintln("IconManger getIcon url=" + url);
		ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if(bitmap == null){
			Tools.debugPrintln("IconManager getSellShop loadResource null");
			return null;
		}
		Bitmap map = bitmap.getImage();
		return map;
	}
	
	/**
	 * @param String url
	 * */
	public static Bitmap getSellTitle(String url)
	{
		Tools.debugPrintln("IconManger getIcon url=" + url);
		ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if(bitmap == null){
			Tools.debugPrintln("IconManager getSellShop loadResource null");
			return null;
		}
		Bitmap map = bitmap.getImage();
		return map;
	}
	
	private static Bitmap[] getVipIcon(int vipSize){
		Bitmap[] vipicon = new Bitmap[vipSize];
		for(int i=0;i<vipSize;i++){
			String url = "/img/newui/vip_"+(i+1)+DWSerializableFactory.EXTENSION_IMG;
			ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
			DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
					DWGameManager.getInstance().m_resourceStatic, head));
			if(bitmap == null){
				Tools.debugPrintln("IconManager getVipIcon(int vipSize) loadResource null");
				vipicon[i] = null;
			}else{				
				vipicon[i] = bitmap.getImage();
			}
		}
		return vipicon;
	}
	
	private static Bitmap[] getWantedIcon() {
		int size = 4;
		Bitmap[] wicon = new Bitmap[size];
		String url = "/img/newui/tongjijb_1"
				+ DWSerializableFactory.EXTENSION_IMG;
		ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG,
				url, 1);
		DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance()
				.loadResource(DWGameManager.getInstance().m_resourceStatic,
						head));
		if (bitmap == null) {
			Tools.debugPrintln("IconManager getVipIcon(int vipSize) loadResource null");
			wicon[0] = null;
		} else {
			wicon[0] = bitmap.getImage();
		}

		url = "/img/newui/tongjiyb_1" + DWSerializableFactory.EXTENSION_IMG;
		head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if (bitmap == null) {
			Tools.debugPrintln("IconManager getVipIcon(int vipSize) loadResource null");
			wicon[1] = null;
		} else {
			wicon[1] = bitmap.getImage();
		}
		
		url = "/img/newui/tongjish_1" + DWSerializableFactory.EXTENSION_IMG;
		head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if (bitmap == null) {
			Tools.debugPrintln("IconManager getVipIcon(int vipSize) loadResource null");
			wicon[2] = null;
		} else {
			wicon[2] = bitmap.getImage();
		}
		
		url = "/img/newui/tongjish_2" + DWSerializableFactory.EXTENSION_IMG;
		head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
		bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
				DWGameManager.getInstance().m_resourceStatic, head));
		if (bitmap == null) {
			Tools.debugPrintln("IconManager getVipIcon(int vipSize) loadResource null");
			wicon[3] = null;
		} else {
			wicon[3] = bitmap.getImage();
		}
		return wicon;
	}
	
	private static Bitmap[] getFactionIcon()
	{
		Bitmap[] factionIcon = new Bitmap[2];
			String url = "/img/newui/lingyin_1"+DWSerializableFactory.EXTENSION_IMG;
			ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
			DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
					DWGameManager.getInstance().m_resourceStatic, head));
			if(bitmap == null){
				Tools.debugPrintln("IconManager getFactionIcon(0) loadResource null");
				factionIcon[0] = null;
			}else{
				factionIcon[0] = bitmap.getImage();
			}
			url = "/img/newui/tianji_1"+DWSerializableFactory.EXTENSION_IMG;
			head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
			bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
					DWGameManager.getInstance().m_resourceStatic, head));
			if(bitmap == null){
				Tools.debugPrintln("IconManager getFactionIcon(1) loadResource null");
				factionIcon[1] = null;
			}else{				
				factionIcon[1] = bitmap.getImage();
			}
		return factionIcon;
	}
	
	private static Bitmap[] getSoulIcon()
	{
		Bitmap[] soul = new Bitmap[2];
			String url = "/img/newui/xuewei_2"+DWSerializableFactory.EXTENSION_IMG;
			ResHead head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
			DWBitmap bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
					DWGameManager.getInstance().m_resourceStatic, head));
			if(bitmap == null){
				Tools.debugPrintln("IconManager soul(0) loadResource null");
				soul[0] = null;
			}else{
				soul[0] = bitmap.getImage();
			}
			url = "/img/newui/xuewei_1"+DWSerializableFactory.EXTENSION_IMG;
			head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_PNG, url, 1);
			bitmap = ((DWBitmap) ResourceManager.getInstance().loadResource(
					DWGameManager.getInstance().m_resourceStatic, head));
			if(bitmap == null){
				Tools.debugPrintln("IconManager soul(1) loadResource null");
				soul[1] = null;
			}else{				
				soul[1] = bitmap.getImage();
			}
		return soul;
	}
	
	private static Actor[] getSoulActor()
	{
		Actor[] actor = new Actor[2];
		Animation[] anim = new Animation[2];
			String url = "/anim/huo_1.anim";
			//url = "/anim/yanhua_1.anim";
			ResHead head =  new ResHead(DWSerializableFactory.RESOURCE_TYPE_ANIM,
		    		url, 1);
			anim[0] = ((Animation) ResourceManager.getInstance().loadResource(
					DWGameManager.getInstance().m_resourceStatic, head));
			if( anim[0] == null){
				Tools.debugPrintln("IconManager animsoul(0) loadResource null");
			}else{
				actor[0] = new Actor(anim[0]);
				actor[0].activate();
				actor[0].setAction(0, true, true);
			}
			url = "/anim/hunwei_2.anim";
			//url = "/anim/yanhua_2.anim";
			head =  new ResHead(DWSerializableFactory.RESOURCE_TYPE_ANIM,
		    		url, 1);
			anim[1] = ((Animation) ResourceManager.getInstance().loadResource(
					DWGameManager.getInstance().m_resourceStatic, head));
			if(anim[1] == null){
				Tools.debugPrintln("IconManager animsoul(1) loadResource null");
			}else{
				actor[1] = new Actor(anim[1]);
				actor[1].activate();
				actor[1].m_isOnce = true;
				actor[1].setAction(0, false, true);
			}
			anim = null;
		return actor;
	}

}